package com.promfy.wifi;


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.test.AndroidTestCase;
import android.util.Log;

import com.promfy.util.HttpUtil;
import com.promfy.util.TcpUdpUtil;
import com.promfy.util.ZipUtil;

public class TestUtil extends AndroidTestCase{
	private static final String TAG = "test";
	
	/**
	 * 
	 */
	public void testWifi(){
//		WifiAdmin wifiAdmin = new WifiAdmin(getContext());
//		wifiAdmin.OpenWifi(); 
//		wifiAdmin.connct("develop", "Com@Lan2");
		/*
		 *1.获取当前连接状态
		 * 
		 */
		WifiManager mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
		//
//		if (!mWifiManager.isWifiEnabled())
//		{
//			mWifiManager.setWifiEnabled(true);
//			try {
//				Thread.sleep(1000 * 3);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		
		//check if connected
		WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
		String ssid = wifiInfo.getSSID();
		Log.d(TAG, "ssid = " + ssid);
		
		//get available wifi
		List<ScanResult> srList = mWifiManager.getScanResults();
		for(ScanResult sr : srList){
			Log.d(TAG, "ssid = " + sr.SSID + "  " + sr.BSSID);
		}
		
		
		//if did not connect, connect 
		if (!mWifiManager.isWifiEnabled()) { // 如果wifi没有开启，则开启。
			mWifiManager.setWifiEnabled(true);
		}
		ssid = "develop";
		String pwd = "Com@Lan2";
		WifiConfiguration wc = new WifiConfiguration();
		wc.SSID = "\"" + ssid + "\""; // 配置wifi的SSID，即该热点的名称，如：TP-link_xxx
		wc.preSharedKey = "\"" + pwd + "\""; // 该热点的密码
		wc.hiddenSSID = true;
		wc.status = WifiConfiguration.Status.ENABLED;
		wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
		wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
		wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
		wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
		wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
		wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
		int res = mWifiManager.addNetwork(wc);
		Log.d(TAG, "add Network returned " + res);
		boolean b = mWifiManager.enableNetwork(res, true);
		Log.d(TAG, "enableNetwork returned " + b);
		
	
	}

	public void testInA1(){
		WifiAdmin wifiAdmin = new WifiAdmin(getContext());
		if(!wifiAdmin.isConnectedWithShareMe()){
			wifiAdmin.connct(WifiAdmin.SHARE_ME_SSID, WifiAdmin.SHARE_ME_PWD);
			//
		}
	}
	
}
